/**
 * Created by huangxuehua on 2017/11/24.
 */
//userInfo.userid= nUtils.getUrlParam("userid");//获取用户ID

var xpHome = new Vue({
    el:'#app',
    data:{
        imgBaseUrl:nUrls.imgBaseUrl,
        showGoodsList:[],//首页 商品列表信息
        wxAdList:[]//首页轮播信息
    },
    methods:{
        goLunboDetail:function(ad_cat_id){//轮播广告详情
            window.location.href = "./html/detail/ad_detail.html?id="+ad_cat_id;
            //console.log(ad_cat_id.index)
        },
        goGoodsDetail:function(goods_id){//商品详情
            window.location.href = "./html/detail/goods_detail.html?id="+goods_id;
            if(navigator && navigator.onLine === false){

            }
        },
        getWxAd:function(){
            $.ajax({
                url: nUrls.getWxAdUrl,
                type:'post',
                success:function(data){
                    var result = eval('('+data+')');
                    if(result && result.code == 200){
                        //console.log(result)
                        xpHome.wxAdList = result.data;
                        //console.log(xpHome.wxAdList);

                        //轮播
                        setTimeout(function(){
                            var slide2 = new auiSlide({
                                container:document.getElementById("aui-slide2"),
                                // "width":300,
                                "height":'auto',
                                "speed":300,
                                "autoPlay":2000, //自动播放
                                "pageShow":true,
                                "loop":true,
                                "pageStyle":'dot',
                                'dotPosition':'center'
                            });
                        },(300));
                    }
                },
                error:function(){
                    console.log("没有更多信息")
                }
            });
        },
        goAdDetail:function(idx){
            console.log("--idx--",idx)
            var ad=  xpHome.wxAdList;
            console.log("--ad-",ad)
            if(ad){
                window.location.href="https://"+ad[idx].ad_link;
            }
        },
        goodsList:function(){//动态获取 商品 并展示
            $.ajax({
                url: nUrls. getThreeGoodsInfo,
                type:'post',
                success:function(data){
                    var result = eval('('+data+')');
                    if(result && result.code == 200){
                        //console.log(result)
                        xpHome.showGoodsList = result.data;
                       console.log(xpHome.showGoodsList);
                    }
                },
                error:function(){
                    console.log("没有更多商品")
                }
            });
        },
        goActivity:function(){  //跳转到活动详情页面
            window.location.href="./html/activity.html"
        },
        getToken:function(){ //获取token信息
            var data={
                "userid":userInfo.userid // nUtils.getUrlParam("userid");
            }
            $.ajax({
                url:nUrls.getTokenInfo,
                type:"POST",
                data:data,
                success:function(data){
                    //console.log("++++")
                    var result = eval('('+data+')');
                    if(result && result.code == 200) {
                        var token = result.data.access_token;
                        //console.log("'+token++",token)
                        window.localStorage.setItem("access_token",token);
                    }
                },
                error:function(){
                    console.log("获取token失败");
                }
            })
        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        }
    }
});
$(function(){
    xpHome.getToken();//获取token信息
    xpHome.goodsList();//获取商品
    xpHome.getWxAd();//获得首页轮播广告

    window.localStorage.setItem("faPiaoInfo","");//清空buy页面发票信息
    window.localStorage.setItem("couponInfo","")//清空Buy页面优惠券信息

    if(sessionStorage.opened){    //sessionStorage缓存
        //console.log('窗口是刷新页面,不是新打开')
        $("#imgBg1").css("display","none");  //测试完成打开
        $("#body1").css("display","block");
    }else{
        //console.log('窗口是新打开')
        $("#imgBg1").css("display","block");
        $("#body1").css("display","block");
    }
    sessionStorage.setItem('opened','true');
    touchMoveCant("#imgBg1");
})
$(".closeBtn").click(function(){ //点击关闭遮罩层
    $("#imgBg1").css("display","none");
})
$("#goActivity").click(function(){
    window.location.href="./html/activity.html"
})

function touchMoveCant(ele){//ios 等其他型号手机 滑动问题
    document.querySelector(ele).addEventListener("touchmove", function(e){
        e.preventDefault();
    });
}
//底部菜单栏跳转
var tab = new auiTab({
    element:document.getElementById("footer"),
    index:1 //当前下标选择的位置
},function(ret){
    if(ret){
        if(ret.index == 1){
            window.location.href = "#";
        }else if(ret.index == 2){
            window.location.href = "./html/shop_cart.html";
        }else if(ret.index == 3){
            window.location.href = "./html/my_center.html";
        }
    }
});

$(function(){//返回顶部
$("#back-to-top").hide();
    window.onscroll = function(){
        var height =  document.documentElement.scrollTop;
        if(height<=500){
            $("#back-to-top").hide();
        }else{
            $("#back-to-top").show()
    }
};
});


//$(function(){  //广告入口页面
    //if(sessionStorage.opened){    //sessionStorage缓存
    //       //console.log('窗口是刷新页面,不是新打开')
    //    //$("#imgBg1").hide();
    //    $("#imgBg1").css("display","none");
    //    //$("#body1").show();
    //    $("#body1").css("display","block");
    //      }else{
    //         //console.log('窗口是新打开')
    //    //$("#body1").hide();
    //    $("#body1").css("display","none");
    //    setTimeout(function(){
    //        //$("#imgBg1").show();
    //        $("#imgBg1").css("display","block");
    //    },8000);
    //    setTimeout(function(){
    //        //$("#body1").show();
    //        $("#body1").css("display","block");
    //        //$("#imgBg1").hide();
    //        $("#imgBg1").css("display","none");
    //    },8000)
    //
    //      }
    // sessionStorage.setItem('opened','true');
//})
